<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Question extends Model
{
    protected $fillable = ['category_id','content', 'type', 'options', 'answer', 'explanation', 'status', 'teacher_id'];

    // 转换选项为数组（存储时为JSON，查询时自动转为数组）
    protected $casts = [
        'options' => 'array',
    ];

    // 关联试卷
    public function papers()
    {
        return $this->belongsToMany(Paper::class, 'paper_questions');
    }

    // 关联分类
    public function category()
    {
        return $this->belongsTo(QuestionsCategory::class, 'category_id');
    }
    
    // 关联教师
    public function teacher()
    {
        return $this->belongsTo(Admin::class, 'teacher_id');
    }
}
